﻿@model EquipmentStockListModel

@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    //page title
    ViewBag.Title = "当前库存";
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Stock List");
}

@Html.AntiForgeryToken()
<div class="content-header clearfix">
    <h1 class="pull-left">
        当前库存
    </h1>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default panel-search">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <div class="col-md-1">
                                    <div class="label-wrapper"><label class="control-label" for="SearchCategoryId" title="">分类</label></div>
                                </div>
                                <div class="col-md-2">
                                    @Html.EditorFor(model => model.SearchCategoryId, new { SelectList = Model.AvailableCategories })
                                </div>
                                <div class="col-md-1">
                                    <div class="label-wrapper"><label class="control-label" for="SearchName" title="">名称</label></div>
                                </div>
                                <div class="col-md-2">
                                    @Html.NopEditorFor(model => model.SearchName)
                                </div>
                                <div class="col-md-3">
                                    <button type="button" id="search-categories" class="btn btn-primary"><i class="fa fa-search"></i>@T("Admin.Common.Search")</button>
                                    <button type="button" id="cancel-categories" class="btn btn-default"><i class="fa fa-refresh"></i>重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="categories-grid"></div>

                    <script>
                        $(document).ready(function() {
                            $("#categories-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("List", "EquipmentStock"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: additionalData
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors"
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    pageSize: @(defaultGridPageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    pageSizes: [@(gridPageSizes)],
                                    @Html.Partial("_GridPagerMessages")
                                },
                                editable: {
                                    confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                    mode: "inline"
                                },
                                scrollable: false,
                                columns: [
                                    {
                                        field: "EquipmentName",
                                        title: "名称",
                                        headerAttributes: { style: "text-align:center" },
                                    }, {
                                        field: "Manufacturer",
                                        title: "厂商",
                                        width: 200,
                                        headerAttributes: { style: "text-align:center" },
                                        template: '<span title="#=Technician||""# #=TechnicianContact||""#" class="tip">#=Manufacturer||""#</span>'
                                    }, {
                                        field: "ProductionDate",
                                        title: "生产时间",
                                        width: 100,
                                        type: "date",
                                        format: "{0:yyyy/MM/dd}",
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    },{
                                        field: "Price",
                                        title: "价格",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:right" },
                                        format:"{0:N2}"
                                    }, {
                                        field: "Amount",
                                        title: "可用数量",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:right" },
                                    }, {
                                        field: "Freeze",
                                        title: "冻结数量",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:right" },
                                    }, {
                                        field: "Published",
                                        title: "发布",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                        template: '# if(Published) {# <i class="fa fa-check true-icon"></i> #} else {# <i class="fa fa-close false-icon"></i> #} #'
                                    }, {
                                        field: "DisplayOrder",
                                        title: "排序",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                    }, {
                                        field: "Id",
                                        title: "操作",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                        template: '<a class="btn btn-default" href="Edit/#=Id#"><i class="fa fa-pencil"></i>@T("Admin.Common.Edit")</a>'
                                    }
                                ]
                            });
                        });
                    </script>

                    <script type="text/javascript">
                        $(document).ready(function() {
                            //search button
                            $('#search-categories').click(function() {
                                //search
                                var grid = $('#categories-grid').data('kendoGrid');
                                grid.dataSource.page(1); //new search. Set page size to 1
                                //grid.dataSource.read(); we already loaded the grid above using "page" function
                                return false;
                            });
                            //cancel button
                            $('#cancel-categories').click(function () {
                                //cancel
                                var grid = $('#categories-grid').data('kendoGrid');
                                $('#@Html.FieldIdFor(model => model.SearchName)').val('');
                                $('#@Html.FieldIdFor(model => model.SearchCategoryId)').val('0');
                                $("#select_menu").attr("value", "全部");
                                grid.dataSource.page(1); //new search. Set page size to 1
                                //grid.dataSource.read(); we already loaded the grid above using "page" function
                                return false;
                            });

                            $("#@Html.FieldIdFor(model => model.SearchName)").keydown(function(event) {
                                if (event.keyCode == 13) {
                                    $("#search-categories").click();
                                    return false;
                                }
                            });
                        });

                        function additionalData() {
                            var data = {
                                SearchCategoryId: $('#@Html.FieldIdFor(model => model.SearchCategoryId)').val(),
                                SearchName: $('#@Html.FieldIdFor(model => model.SearchName)').val()
                            };
                            addAntiForgeryToken(data);
                            return data;
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>